package com.araaya.eslimsmobile;


/*import com.araaya.geoMapper.PointCapture.MyOverlay;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;*/
 

public class MyItemizedOverlay/* extends ItemizedOverlay*/ {
   /* private ArrayList< OverlayItem > mOverlays = new ArrayList< OverlayItem >();
    Context mContext;
    
    public static boolean isToutch; 
 
 
    public MyItemizedOverlay(Drawable marker) {
        super(boundCenterBottom(marker));
    }
 
    public MyItemizedOverlay(Drawable marker, Context context) {
        super(boundCenterBottom(marker));
        mContext = context;
    }
 
    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }
 
    @Override
    protected OverlayItem createItem(int i) {
        return mOverlays.get(i);
    }
 
    @Override
    public int size() {
        return mOverlays.size();
    }
 
    @Override
    protected boolean onTap(int i) {
            //when you tap on the marker this will show the informations provided by you when you create in the
            //main class the OverlayItem
            OverlayItem item = mOverlays.get(i);

            GeoPoint gpoint = item.getPoint();
            double lat = gpoint.getLatitudeE6()/1e6;
            double lon = gpoint.getLongitudeE6()/1e6;
            //String toast = "Title: "+item.getTitle();
            //toast += "\nText: "+item.getSnippet();
            //toast += 	"\nSymbol coordinates: Lat = "+lat+" Lon = "+lon+" (microdegrees)";
            //Toast.makeText(MapOverlayDemo.context, toast, Toast.LENGTH_LONG).show();
            String toast = " coordinates :" +
            		"\n Lat = "+ lat + 
            		"\n Lon = " + lon;


            AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
            dialog.setTitle(item.getTitle());
            //dialog.setMessage(item.getSnippet());
            dialog.setMessage(toast);
            dialog.show();
            return true;
        }
    
    @Override
    public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    {   
        //---when user lifts his finger---
        if (event.getAction() == 1 && isToutch) {                
            GeoPoint p = mapView.getProjection().fromPixels(
                (int) event.getX(),
                (int) event.getY());
                Toast.makeText(mContext, 
                    p.getLatitudeE6() / 1E6 + "," + 
                    p.getLongitudeE6() /1E6 , 
                    Toast.LENGTH_SHORT).show();
                
                isToutch=false;
                manualMapAlert(mContext, p.getLatitudeE6() / 1E6, p.getLongitudeE6() /1E6);

        }                            
        return false;
    }   
    
    private void manualMapAlert(final Context ctx, final double lat,final double lon) {

		try {
			

			GeoPoint gpoint = item.getPoint();
			final double lat = gpoint.getLatitudeE6() / 1e6;
			final double lon = gpoint.getLongitudeE6() / 1e6;
			// Toast.makeText(ctx, toast, Toast.LENGTH_LONG).show();
			String txt = "GPS Point : ";
			txt += " \n Lat : " + lat + " " + "\n Lon : " + lon + ""
					+ "\n\n Do you want to add this point?";

			AlertDialog.Builder alt_bld = new AlertDialog.Builder(ctx);
			alt_bld.setMessage(txt)
					.setCancelable(false)
					.setPositiveButton("Add Point",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int id) {
									
									
									// Add point
									HashMap<String, String> map = new HashMap<String, String>();
									map.put("lon", "" + lon);
									map.put("lat", "" + lat);
									map.put("alt", "" + 0);
									KmlHome.pointList.add(map);

									String toast = "The Point is added.";
									toast += "\n coordinates AdjacentLand: Lat = "
											+ lat + " Lon = " + lon;

									Log.d("PointListSize=", ""
											+ KmlHome.pointList.size());
									toast += "\n Point List Size : "
											+ KmlHome.pointList.size();

									Toast.makeText(ctx, toast,
											Toast.LENGTH_LONG).show();
									
									int latVal = (int) (lat * 1E6);
									int logVal = (int) (lon * 1E6);

									GeoPoint point = new GeoPoint(latVal, logVal);
									// mapView.getController().animateTo(point);
									OverlayItem overlayitem = new OverlayItem(point, "", "");
									
									addOverlay(overlayitem);
									
									return;

								}
							})

					.setNeutralButton("No",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int id) {

								
									dialog.cancel();

									return;

								}
							});

			AlertDialog alert = alt_bld.create();
			alert.setTitle("Manual Map Point");
			// Icon for AlertDialog
			alert.setIcon(R.drawable.land);
			alert.show();
			
			

		} catch (Exception e) {
			e.printStackTrace();
		}

	}*/
}
